from django.http import HttpResponse, HttpResponseRedirect
from django.template import loader
from django.db import connection
from django.utils.dateparse import parse_date
from django.urls import reverse
from datetime import datetime
from django.shortcuts import render
from django.http import JsonResponse
import json
from urllib.parse import unquote

COLUMN_NAMES = [
    '序号','编号','用途', '密级', '部门', '责任人', '设备类型',
    '启用日期'
]

def index(request):
    with connection.cursor() as cursor:
        cursor.execute('SELECT * FROM TEST_copy1')
        datas = cursor.fetchall()

    # 将元组列表转换为字典列表
    datas = [dict(zip(COLUMN_NAMES, data)) for data in datas]

    template = loader.get_template('index.html')
    context = {
        'datas': datas,
    }
    return HttpResponse(template.render(context, request))
